package com.ugoodtech.mdcc.client.service.impl;

import com.ugoodtech.mdcc.client.dto.JsonResponse;
import com.ugoodtech.mdcc.client.service.LeanPaintReportService;
import com.ugoodtech.mdcc.core.domain.Station;
import com.ugoodtech.mdcc.core.domain.StationLeanPaintReport;
import com.ugoodtech.mdcc.core.domain.StationLeanPaintSatisfactionReport.LeanPaintQuestion;
import com.ugoodtech.mdcc.core.domain.StationLeanPaintSatisfactionReport.StationLeanPaintSatisfactionReport;
import com.ugoodtech.mdcc.core.repository.StationLeanPaintReportRepository;
import com.ugoodtech.mdcc.core.repository.StationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

@Service
public class LeanPaintReportServiceImpl implements LeanPaintReportService {

    @Autowired
    private StationLeanPaintReportRepository stationLeanPaintReportRepository;

    @Autowired
    private StationRepository stationRepository;

    public JsonResponse statistical(Station station, Long reportId) {
        StationLeanPaintSatisfactionReport slpsr = new StationLeanPaintSatisfactionReport();
        StationLeanPaintReport stationLeanPaintReport = stationLeanPaintReportRepository.findOne(reportId);
        if (stationLeanPaintReport == null) {
            JsonResponse.errorResponseWithError("抱歉", "未找到此报告");
        }
        slpsr.setCreateTimeStr(stationLeanPaintReport.getCreationTimeStr());
        slpsr.setServiceComapny(stationLeanPaintReport.getServiceStaffName());
        slpsr.setContantPerson(stationLeanPaintReport.getContactName());
        slpsr.setServoceCpmpanyAddress("");
        List<LeanPaintQuestion> leanPaintQuestionList = new ArrayList<>();

        Class cls = stationLeanPaintReport.getClass();
        Field[] fields = cls.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field f = fields[i];
            f.setAccessible(true);
            LeanPaintQuestion question = new LeanPaintQuestion();

            try {
                System.out.println("属性名:" + f.getName() + " 属性值:" + f.get(stationLeanPaintReport));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }


        }
        return null;

    }
}
